/*
*******************************************************************
* Copyright (c) 2003-2020  TECHNOLOGY CO.,LTD.
* All Rights Coding Guideline for Programming Language C R00
Confidential Document - Reproduction, Disclosure and Circulation without authorization is prohibited
* Filename : Key.c
* Project : 06_Button_control_LED_light
* Description :
* Note(s) :
* Update Record:
* Version   Date          Modified by     Why & What is modified
* 00.00     YYYY.MM.DD    Á¢Ð¾Ç¶ÈëÊ½       Initial Version
*******************************************************************
*/
#include"Key.h"

KeyState g_E_key_state = KEY_RELEASED;
static uint8_t Key_Init(void)
{
    //This section is generated by Cube
	return 0;
}

static uint8_t Key_GetState(void)
{
    if(HAL_GPIO_ReadPin(KEY_PORT,KEY_PIN) == 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

void key_task_runnable(void)
{
    static uint8_t task_state = 0;
    uint8_t pin_state = GPIO_PIN_RESET;
    if(task_state == 0)
    {
        if(Key_Init() == 0)
        {
            task_state = 1;
        }
    }
    else
    {
        pin_state = Key_GetState();
        if(pin_state == 0)
        {
            if(g_E_key_state == KEY_RELEASED)
            {
                HAL_Delay(KEY_FILTER_TIME);
                pin_state = Key_GetState();
                if(pin_state == 0)
                {
                    g_E_key_state = KEY_PRESSED;
                }
                else
                {
                    g_E_key_state = KEY_RELEASED;
                }
            }
        }
        else
        {
            g_E_key_state = KEY_RELEASED;
        }
    }
}
